package com.pss.mail;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailException;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @创建人 czj
 * @创建时间 2021/9/15
 * @描述
 */
@Service
public class SendMailService {

    @Autowired
    private JavaMailSender mailSender;

    @RequestMapping("/sendEmail")
    @ResponseBody
    public boolean sendEmail() {
        // new 一个简单邮件消息对象
        SimpleMailMessage message = new SimpleMailMessage();
        // 和配置文件中的的username相同，相当于发送方
        message.setFrom("czj_folson@163.com");
        // 收件人邮箱
        message.setTo("757892057@qq.com");
        // 抄收一份
        message.setCc("");
        // 标题
        message.setSubject("shares set");
        message.setText("1i23");
        // 发送
        try {
            mailSender.send(message);
        } catch (MailException ex) {
            System.err.println(ex.getMessage());
            return false;
        }
        return true;
    }



}
